﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;

namespace shop.Model
{

    /// <summary> 用法 MyMapper.GetMapper().Map() </summary>
    public class MyMapper: Profile
    {
        public MyMapper()
        {
            // source -> target
            //CreateMap<Student, StudentCopy>()

            //.ForMember非必须，当两个类需要映射的属性名称不一致时可以使用此方法，来指定哪个属性应该映射为哪个属性，例如此处Student.Name需要映射为StudentCopy.FullName
            //CreateMap<Student, StudentCopy>().ForMember(dest => dest.FullName, option => option.MapFrom(source => source.Name));


            CreateMap<tradeData, TradeLogisticsData>();


        }


        static MapperConfiguration _config;
        static IMapper _mapper;


        public static MapperConfiguration GetConfig()
        {
            if (_config == null)
            {
                _config = new MapperConfiguration(cfg => cfg.AddProfile(new MyMapper()));
            }

            return _config;
        }


        public static IMapper GetMapper()
        {
            if (_mapper == null)
            {
                _mapper = GetConfig().CreateMapper();
            }

            return _mapper;
        }


    }

}
